 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.classesBasicas.jogo;
using Biblioteca.fachada;

namespace Desktop.views.cruds.crudsJogo.crudReserva
{
    public partial class MenuReserva : Form
    {
        private TelaInicial telaInicial;
        private Reserva reserva = new Reserva();
        private Fachada fachada = new Fachada();
        private List<Reserva> listaReserva;

        
        public MenuReserva(TelaInicial telaInicial)
        {
            this.telaInicial = telaInicial;

            telaInicial.Hide();
            InitializeComponent();
        }

        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroReserva cadastroReserva = new CadastroReserva(this);
            cadastroReserva.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void MenuReserva_Load(object sender, EventArgs e)
        {
            carregarGridViewReserva();
        }

        private void MenuReserva_FormClosed(object sender, FormClosedEventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void dataGridViewReserva_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewReserva.Rows[e.RowIndex];

                reserva.Id = row.Cells[0].Value.ToString();
                reserva.Data = row.Cells[1].Value.ToString();
                reserva.Horario = row.Cells[2].Value.ToString();
                reserva.Duracao = row.Cells[3].Value.ToString();
                reserva.QuantidadeJogadores = row.Cells[4].Value.ToString();
                reserva.Campo = new Campo();
                reserva.Campo.Id = row.Cells[5].Value.ToString();
                
                AlterarRemoverReserva alterar = new AlterarRemoverReserva(this, reserva);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewReserva()
        {
            listaReserva = fachada.listarReserva();

            dataGridViewReserva.Rows.Clear();
            dataGridViewReserva.ColumnCount = 6;
            dataGridViewReserva.ColumnHeadersVisible = true;
            dataGridViewReserva.AllowUserToAddRows = false;

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewReserva.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;
            
            //dataGridViewReserva.DataSource = listaReserva;

            this.dataGridViewReserva.Columns[0].Name = "ID";
            this.dataGridViewReserva.Columns[1].Name = "DATA";
            this.dataGridViewReserva.Columns[2].Name = "HORARIO";
            this.dataGridViewReserva.Columns[3].Name = "DURACAO";
            this.dataGridViewReserva.Columns[4].Name = "QTD_JOGADORES";
            this.dataGridViewReserva.Columns[5].Name = "ID_CAMPO";

            foreach (Reserva elemento in listaReserva) 
            {
                dataGridViewReserva.Rows.Add(elemento.Id, elemento.Data, elemento.Horario, elemento.Duracao, elemento.QuantidadeJogadores, elemento.Campo.Id);
            }          
            
        }
        
    }
}
